package cn.sdormitory.controller.canteen;


import cn.sdormitory.canteen.service.CanteenStockDetailService;
import cn.sdormitory.canteen.vo.CanteenBuyVO;
import cn.sdormitory.canteen.vo.CanteenStockDetailVO;
import cn.sdormitory.common.api.CommonPage;
import cn.sdormitory.common.api.CommonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@Api(tags = "canteen-stock=> 食堂原料出入库")
@RequestMapping("/canteen/stock")
public class CanteenStockDetailController {

    @Autowired
    private CanteenStockDetailService canteenStockDetailService;

    @ApiOperation("getStockPageList => 分页查询库存信息")
    @PostMapping(value = "/getStockPageList")
    public CommonResult<CommonPage<CanteenStockDetailVO>> getStockPageList(@RequestBody Map<String, Object> params){
        CommonPage<CanteenStockDetailVO> pagelist = canteenStockDetailService.getPage(params);
        return CommonResult.success(pagelist);
    }

    @ApiOperation("getBuyPageList => 出库")
    @PostMapping(value = "/outStock")
    public CommonResult<Integer> outStock(@RequestBody CanteenStockDetailVO vo){
        int num = canteenStockDetailService.outStock(vo);
        if(num>0){
            return CommonResult.success();
        }
        return CommonResult.failed();
    }
}
